#define  _CRT_SECURE_NO_WARNINGS 1
/**
 * Definition for a binary tree node.
 * struct TreeNode {
 *     int val;
 *     struct TreeNode *left;
 *     struct TreeNode *right;
 * };
 */
bool prevOrder(struct TreeNode* root, int val)
{
    if (root == NULL)
    {
        return true;
    }
    bool a = prevOrder(root->left, val);
    bool b = prevOrder(root->right, val);
    if (root->val == val && a == b && a == true)
    {
        return true;
    }
    else
    {
        return false;
    }

}

bool isUnivalTree(struct TreeNode* root)
{
    int val = root->val;
    bool a = prevOrder(root, val);
    if (a == true)
    {
        return true;
    }
    return false;
}